//
//  CZCommetCell.swift
//  GZWeibo007
//
//  Created by 姚伟聪 on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class CZCommetCell: UITableViewCell {

    var commentModel : YSPCommentModel?{
    
        didSet{
        
            topView.commentModel = commentModel
            contentLab.text = commentModel?.text
            print("内部的\(contentLab.text)")
            
        }
    
    }
    
    //MARK: - 系统初始化方法
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
      addUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    
    private func addUI(){
    

        contentView.addSubview(topView)
        contentView.addSubview(contentLab)
        
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: 0, y: 0))
 
        
        contentLab.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: nil, offset: CGPoint(x: 8, y: 68))
        
        // 微博文本宽度约束
         contentView.addConstraint(NSLayoutConstraint(item: contentLab, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))

    }
    
    func rowHeight(commentModel: YSPCommentModel) -> CGFloat {
        // 设置cell的status,cell会根据status里面的内容重新设置每个控件的内容
        self.commentModel = commentModel
        
        print("返回高度的\(commentModel.text)")
        
        
        // 更新布局,系统会根据控件的内容和约束重新布局每个控件位置和大小
        layoutIfNeeded()
        
        // 获取底部视图的最大的Y值
        let maxY = CGRectGetMaxY(contentLab.frame)
        return maxY + 10
    }

    
    //MARK: - 懒加载
    private lazy var textLab: UILabel = {
        let lab = UILabel(color: UIColor.grayColor(), fontSize: 14)
        lab.text = "暂时没有评论"
        return lab

    }()
    
    //顶部view
    private lazy var topView: YCTopView = YCTopView()
    //内容
    private lazy var contentLab: UILabel = {
    
        let lab = UILabel()
        
        lab.numberOfLines = 0
        
        return lab
    
    }()
    
}
